package elements;

import widgets.LinkWidget;

/**
 * @author danielsmw
 *
 */
public class Link {
	
	// What widget visualizes me on canvas?
	LinkWidget widget;
	
	// What nodes do I connect?
	Node left, right;
	
	// How fast is my connection?
	double speed;
	
	/**
	 * 
	 * @param Node a - One of the nodes on the link.
	 * @param Node b - The other node on the link.
	 * @param double s - The speed of the connection between the links.
	 * 					 This should be positive if a->b, negative if a<-b
	 */
	
	public Link (Node a, Node b) {
		left = a;
		right = b;
		registerWithNode(left);
		registerWithNode(right);
	}
	
	public Node[] getNodes() {
		Node[] list = {left, right};
		return list;
	}
	
	public double getSpeed() {
		return speed;
	}
	
	public void associateWithWidget(LinkWidget lw, boolean remoteRequest) {
		widget = lw;
	}
	
	private void associateWithWidget(LinkWidget lw) {
		widget = lw;
		lw.associateWithLink(this, true);
	}
	
	public void registerWithNode(Node n) {
		n.addConnection(this);
	}
}
